import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({  
    state: {  
		/**
		 * 是否需要强制登录
		 */
        login: false,
		token: '', 
		openid: '',
        avatarUrl: '',  
		gender: '',
		userId: '',
		userName: '',
        nickName: '',
		wxNickName: ''
    },  
    mutations: {  
        setUser(state, userInfo) {   
            console.log("setUser:", userInfo);
			if (userInfo != undefined){
				state.login = true;  
				state.token = userInfo.token;  
				state.gender = userInfo.gender;
				state.nickName = userInfo.nickName;
				state.avatarUrl = userInfo.avatarUrl; 
				state.userId = userInfo.id;
				state.userName = userInfo.username;
				state.wxNickName = userInfo.wxNickName;
			}
        }, 
		setOpenid(state, openid){
			state.openid = openid;
		},
		setUserId(state, userId){
			state.userId = userId;
		},
        logout(state) {  
            state.login = false; 
			state.openid = '';
			state.gender = '';
            state.token = '';  
            state.nickName = '';  
            state.avatarUrl = '';  
			state.userId = '';
			state.userName = '';
        }  
    }  
})

export default store